package com.huawei.hms.framework.common;

import android.text.TextUtils;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLProtocolException;

public class ExceptionCode {
    public static final int CANCEL = 1104;
    private static final String CONNECT = "connect";
    public static final int CONNECTION_ABORT = 110205;
    public static final int CONNECTION_REFUSED = 110209;
    public static final int CONNECTION_RESET = 110204;
    public static final int CONNECT_FAILED = 110206;
    public static final int CRASH_EXCEPTION = 1103;
    public static final int INTERRUPT_CONNECT_CLOSE = 110214;
    public static final int INTERRUPT_EXCEPTION = 110213;
    public static final int NETWORK_IO_EXCEPTION = 1102;
    public static final int NETWORK_UNREACHABLE = 110208;
    private static final String READ = "read";
    public static final int READ_ERROR = 110203;
    public static final int ROUTE_FAILED = 110207;
    public static final int SOCKET_CLOSE = 110215;
    public static final int SOCKET_CONNECT_TIMEOUT = 110221;
    public static final int SOCKET_READ_TIMEOUT = 110223;
    public static final int SOCKET_TIMEOUT = 110200;
    public static final int SOCKET_WRITE_TIMEOUT = 110225;
    public static final int SSL_HANDSHAKE_EXCEPTION = 110211;
    public static final int SSL_PEERUNVERIFIED_EXCEPTION = 110212;
    public static final int SSL_PROTOCOL_EXCEPTION = 110210;
    public static final int UNABLE_TO_RESOLVE_HOST = 110202;
    public static final int UNEXPECTED_EOF = 110201;
    private static final String WRITE = "write";

    private static String checkExceptionContainsKey(Exception exception, String... strArr) {
        String str = "";
        String checkStrContainsKey = checkStrContainsKey(StringUtils.toLowerCase(exception.getMessage()), strArr);
        if (TextUtils.isEmpty(checkStrContainsKey)) {
            for (StackTraceElement stackTraceElement : exception.getStackTrace()) {
                checkStrContainsKey = checkStrContainsKey(StringUtils.toLowerCase(stackTraceElement.toString()), strArr);
                if (!TextUtils.isEmpty(checkStrContainsKey)) {
                    break;
                }
            }
        }
        return checkStrContainsKey;
    }

    private static String checkStrContainsKey(String str, String... strArr) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        for (Object obj : strArr) {
            if (str.contains(obj)) {
                return obj;
            }
        }
        return "";
    }

    public static int getErrorCodeFromException(Exception exception) {
        if (exception == null) {
            return NETWORK_IO_EXCEPTION;
        }
        if (!(exception instanceof IOException)) {
            return CRASH_EXCEPTION;
        }
        String message = exception.getMessage();
        if (message == null) {
            return NETWORK_IO_EXCEPTION;
        }
        String toLowerCase = StringUtils.toLowerCase(message);
        int errorCodeFromMsg = getErrorCodeFromMsg(toLowerCase);
        return errorCodeFromMsg != NETWORK_IO_EXCEPTION ? errorCodeFromMsg : exception instanceof SocketTimeoutException ? getErrorCodeSocketTimeout(exception) : exception instanceof ConnectException ? CONNECT_FAILED : exception instanceof NoRouteToHostException ? ROUTE_FAILED : exception instanceof SSLProtocolException ? SSL_PROTOCOL_EXCEPTION : exception instanceof SSLHandshakeException ? SSL_HANDSHAKE_EXCEPTION : exception instanceof SSLPeerUnverifiedException ? SSL_PEERUNVERIFIED_EXCEPTION : exception instanceof UnknownHostException ? UNABLE_TO_RESOLVE_HOST : exception instanceof InterruptedIOException ? toLowerCase.contains("connection has been shut down") ? INTERRUPT_CONNECT_CLOSE : INTERRUPT_EXCEPTION : errorCodeFromMsg;
    }

    private static int getErrorCodeFromMsg(String str) {
        return str.contains("unexpected end of stream") ? UNEXPECTED_EOF : str.contains("unable to resolve host") ? UNABLE_TO_RESOLVE_HOST : str.contains("read error") ? READ_ERROR : str.contains("connection reset") ? CONNECTION_RESET : str.contains("software caused connection abort") ? CONNECTION_ABORT : str.contains("failed to connect to") ? CONNECT_FAILED : str.contains("connection refused") ? CONNECTION_REFUSED : str.contains("connection timed out") ? SOCKET_CONNECT_TIMEOUT : str.contains("no route to host") ? ROUTE_FAILED : str.contains("network is unreachable") ? NETWORK_UNREACHABLE : str.contains("socket closed") ? SOCKET_CLOSE : NETWORK_IO_EXCEPTION;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static int getErrorCodeSocketTimeout(java.lang.Exception r6) {
        /*
        r3 = 2;
        r2 = 1;
        r0 = 0;
        r1 = 3;
        r1 = new java.lang.String[r1];
        r4 = "connect";
        r1[r0] = r4;
        r4 = "read";
        r1[r2] = r4;
        r4 = "write";
        r1[r3] = r4;
        r4 = checkExceptionContainsKey(r6, r1);
        r1 = -1;
        r5 = r4.hashCode();
        switch(r5) {
            case 3496342: goto L_0x002f;
            case 113399775: goto L_0x0039;
            case 951351530: goto L_0x0026;
            default: goto L_0x001e;
        };
    L_0x001e:
        r0 = r1;
    L_0x001f:
        switch(r0) {
            case 0: goto L_0x0043;
            case 1: goto L_0x0047;
            case 2: goto L_0x004b;
            default: goto L_0x0022;
        };
    L_0x0022:
        r0 = 110200; // 0x1ae78 float:1.54423E-40 double:5.4446E-319;
    L_0x0025:
        return r0;
    L_0x0026:
        r2 = "connect";
        r2 = r4.equals(r2);
        if (r2 == 0) goto L_0x001e;
    L_0x002e:
        goto L_0x001f;
    L_0x002f:
        r0 = "read";
        r0 = r4.equals(r0);
        if (r0 == 0) goto L_0x001e;
    L_0x0037:
        r0 = r2;
        goto L_0x001f;
    L_0x0039:
        r0 = "write";
        r0 = r4.equals(r0);
        if (r0 == 0) goto L_0x001e;
    L_0x0041:
        r0 = r3;
        goto L_0x001f;
    L_0x0043:
        r0 = 110221; // 0x1ae8d float:1.54453E-40 double:5.44564E-319;
        goto L_0x0025;
    L_0x0047:
        r0 = 110223; // 0x1ae8f float:1.54455E-40 double:5.44574E-319;
        goto L_0x0025;
    L_0x004b:
        r0 = 110225; // 0x1ae91 float:1.54458E-40 double:5.44584E-319;
        goto L_0x0025;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hms.framework.common.ExceptionCode.getErrorCodeSocketTimeout(java.lang.Exception):int");
    }
}
